package com.ht.utils.htmlBean;

import lombok.Data;

import java.util.LinkedList;
import java.util.List;

@Data
public class TC {

    private Line top = null;
    private Line bottom = null;
    private Line left = null;
    private Line right = null;
    private Integer gridSpan;
    private Integer rowSpan;
    private String color;
    private String background_color;
    private List<PPR> ppr = new LinkedList<>();
    private float width = -1;
    private boolean isHidden;
    public void addRowSpan(){
        this.rowSpan = this.rowSpan+1;
    }
    public void addPpr(PPR ppr){
        this.ppr.add(ppr);
    }
    String toHtml() {
        StringBuilder html = new StringBuilder("<td ");
        if (this.rowSpan != null) {
            html.append(" rowspan='").append(this.rowSpan).append("' row-style='restart'");
        }
        if (this.gridSpan != null) {
            html.append(" colspan = '").append(this.gridSpan).append("'");
        }
        if (this.isHidden) {
            html.append(" hidden='hidden' row-style='continue'");
        }
        html.append(" style=\"");
        if (this.top != null) {
            if (this.top.getType() != null) {
                html.append("border-top-style:").append(Line.converLineType(this.top.getType())).append(";");
            }
            if (this.top.getColor() != null) {
                html.append("border-top-color:").append(Line.converColor(this.top.getColor())).append(";");
            }
            if (this.top.getSz() > 0) {
                html.append("border-top-width:").append(this.top.getSz() / 250 * 12 / 0.75).append("px;");
            }
        }
        if (this.bottom != null) {
            if (this.bottom.getType() != null) {
                html.append("border-bottom-style:").append(Line.converLineType(this.bottom.getType())).append(";");
            }
            if (this.bottom.getColor() != null) {
                html.append("border-bottom-color:").append(Line.converColor(this.bottom.getColor())).append(";");
            }
            if (this.bottom.getSz() > 0) {
                html.append("border-bottom-width:").append(this.bottom.getSz() / 250 * 12 / 0.75).append("px;");
            }
        }
        if (this.left != null) {
            if (this.left.getType() != null) {
                html.append("border-left-style:").append(Line.converLineType(this.left.getType())).append(";");
            }
            if (this.left.getColor() != null) {
                html.append("border-left-color:").append(Line.converColor(this.left.getColor())).append(";");
            }
            if (this.left.getSz() > 0) {
                html.append("border-left-width:").append(this.left.getSz() / 250 * 12 / 0.75).append("px;");
            }
        }
        if (this.right != null) {
            if (this.right.getType() != null) {
                html.append("border-right-style:").append(Line.converLineType(this.right.getType())).append(";");
            }
            if (this.right.getColor() != null) {
                html.append("border-right-color:").append(Line.converColor(this.right.getColor())).append(";");
            }
            if (this.right.getSz() > 0) {
                html.append("border-right-width:").append(this.right.getSz() / 250 * 12 / 0.75).append("px;");
            }
        }
        if (this.color != null && !this.color.equals("auto")) {
            html.append("color:").append(this.color).append(";");
        }
        if (this.background_color != null) {
            html.append("background-color:#").append(this.background_color).append(";");
        }
        if (this.width > 0) {
            html.append("width:").append(this.width * 100).append("%;");
        }
        html.append("\">");
        if (this.ppr != null && !this.ppr.isEmpty()) {
            for (PPR one : ppr) {
                html.append(one.toHtml());
            }
        }
        html.append("</td>");
        return html.toString();
    }

}
